//Copyright (c) Microsoft Corporation.  All rights reserved.

#pragma once

using namespace System;
using namespace System::Windows::Forms;
using namespace System::Drawing;
using namespace System::Threading;

namespace  Microsoft { namespace WindowsAPICodePack { namespace DirectX { namespace Controls {

public delegate void RenderHandler();

public ref class RenderControl : public System::Windows::Forms::UserControl
{
public:
    /// <summary>
    /// Constructor
    /// </summary>
    RenderControl()
		{
            SetStyle(ControlStyles::UserPaint, true);
            SetStyle(ControlStyles::AllPaintingInWmPaint, true);            
            UpdateStyles();
		}

protected:
        virtual void OnPaintBackground(PaintEventArgs ^e) override
		{
            if (DesignMode)
            {
                e->Graphics->FillRectangle(
                    SystemBrushes::Control, 
                    System::Drawing::Rectangle(0,0,Width, Height));
            }
        }

        virtual void OnPaint(PaintEventArgs ^e)
            override
        {
            if (DesignMode)
            {               
                e->Graphics->DrawString(
                    "Direct3D Control", 
                    SystemFonts::StatusFont,
                    SystemBrushes::ControlText, 
                    (float)Width / 2, 
                    (float)Height / 2);
            }
            else
            {
                if (Render != nullptr)
                    Render();
            }


        }

public: 
    RenderHandler^ Render;
};
}}}}
